package com.augurit.wf.app.document.converter;


import java.util.ArrayList;
import java.util.List;

import com.augurit.wf.app.document.entity.DocCategory;
import com.augurit.wf.app.document.entity.Document;
import com.augurit.wf.app.document.utils.DateUtil;
import com.augurit.wf.app.document.web.form.DocCategoryForm;
import com.augurit.wf.app.document.web.form.DocumentForm;

public class DocConvert {
	
	public static List<DocCategoryForm> convertCats2Formlist(List<DocCategory> list){
		if(list != null && list.size() > 0){
			List<DocCategoryForm> list2 =new ArrayList<DocCategoryForm>();
			for(DocCategory entity:list){
				DocCategoryForm form=convertCatToForm(entity);
				list2.add(form);
			}
			return list2;
		}else {
			return null;
		}
	}
	
	public static DocCategoryForm convertCatToForm(DocCategory entity){
		if(entity!=null){
			DocCategoryForm form =new DocCategoryForm();
			form.setId(entity.getId());
			form.setInx(entity.getInx());
			form.setName(entity.getName());
			form.setPid(entity.getPid());
			form.setVersion(entity.getVersion());
			return form;
			
		}else{
			return null;
		}
		
	}
	
	public static List<DocumentForm> convertEntityListtoFormList(List<Document> list){
		if(list != null && list.size() > 0){
			List<DocumentForm> list2 =new ArrayList<DocumentForm>();
			for(Document entity:list){
				DocumentForm form=convertToForm(entity);
				list2.add(form);
			}
			return list2;
		}else {
			return null;
		}
		
	}
	
	
	
	public static DocumentForm convertToForm(Document entity){
		if(entity!=null){
			//这里做失效判断并修改
			
			DocumentForm form= new DocumentForm();
			
			form.setCid(entity.getCid());
			form.setDocType(entity.getDocType());
			form.setFileName(entity.getFileName());
			form.setId(entity.getId());
			form.setInx(entity.getInx());
			form.setName(entity.getName());
			form.setPovd(entity.getPovd());
			if(entity.getPovd() != null){
				if(!DateUtil.isOutDate(entity.getPovd())){
					form.setStatus(entity.getStatus());
				}else{
					form.setStatus("失效");
					entity.setStatus("失效");
				}
			}
					
			form.setUrl(entity.getUrl());
			form.setVersion(entity.getVersion());
			return form;
		}else {
			return null;
		}
	}
	
	public static Document convertToEntity(DocumentForm form){
		if(form!=null){
			Document entity=new Document();
			//entity.setId(form.getId());
			entity.setCid(form.getCid());
			entity.setDocType(form.getDocType());
			entity.setFileName(form.getFileName());
			entity.setInx(form.getInx());
			entity.setName(form.getName());
			entity.setPovd(form.getPovd());
			entity.setStatus(form.getStatus());
			entity.setUrl(form.getUrl());
			entity.setVersion(form.getVersion());
			return entity;
		}else {
			return null;
		}
	}

}
